package cn.kgc.springcloud.controller;

import cn.kgc.springcloud.client.OrderClient;
import cn.kgc.springcloud.entity.Order;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * @author: 课工场
 * @since 2023/9/1
 */
@RestController
@RequestMapping("user")
@Slf4j
public class UserController {

    @Autowired
    private OrderClient orderClient;

    @GetMapping("m1")
    public String method1(){
        // 调用order服务中的method1 方法
        String s = orderClient.method1();
        return "UserController method1 ok result = "+s;
    }


    @GetMapping("m2")
    public String method2(Integer id){
        // 调用order服务中的method1 方法
        log.info("===========userController id========= {}",id);
        String s = orderClient.method2(id);
        return "UserController method2 ok result = "+s;
    }

    @GetMapping("m3/{id}")
    public String method3(@PathVariable("id") Integer id){
        // 调用order服务中的method1 方法
        log.info("===========userController id========= {}",id);
        String s = orderClient.method3(id);
        return "UserController method3 ok result = "+s;
    }

    // 数组
    @GetMapping("m4")
    public String method4( Integer[] ids){
        // 调用order服务中的method1 方法
        for (Integer id : ids) {
            log.info("userController id = "+id);
        }
        String s = orderClient.method4(ids);
        return "UserController method4 ok result = "+s;
    }

    @GetMapping("m5")
    public String method5(Integer id,String name){
        // 调用order服务中的method1 方法
        log.info("id = {},name= {}",id,name);
        String s = orderClient.method5(id,name);
        return "UserController method5 ok result = "+s;
    }

    @GetMapping("m6")
    public String method6(Integer id,String name){
        // 调用order服务中的method1 方法
        log.info("id = {},name= {}",id,name);
        Order order = new Order();
        order.setId(id);
        order.setProductName(name);
        String s = orderClient.method6(order);
        return "UserController method6 ok result = "+s;
    }

    @GetMapping("m7")
    public String method7(Integer id){
        // 调用order服务中的method1 方法
        Order order = orderClient.method7(id);
        return "UserController method7 ok result = "+order;
    }
}
